// //浅拷贝和深拷贝 数组  深拷贝在浏览器才能使用 V8引擎不适用 structuredClone()
// let arr1 = [1, 2, 3, 4, 5];
// let arr2 = [];
// for (let i = 0; i < arr1.length; i++) {
//     arr2[i] = arr1[i];
// }
// console.log(arr2);
// console.log(arr1);
//
// let arr3 = arr1.slice();
// console.log(arr3);
// arr1[0] = 1000;
// console.log(arr3);
// console.log(arr1);


//对象的浅拷贝 只有一层
// let obj1={name:'luojinsheng',age:20};
// let obj2={};
// for (const obj1Key in obj1) {
//     obj2[obj1Key] = obj1[obj1Key];
// }
// console.log(obj1);
// console.log(obj2);

// let obj1={name:'luojinsheng',age:20};
// let obj2={name:'yangxiaoxiao',sex :'nv'};
// Object.assign(obj2,obj1);
// obj1.name = 'luodada';
// console.log(obj1);
// console.log(obj2);

// let obj1={name:'luojinsheng',age:20,flag:{x:100,y:200}};
// let obj2={name:'yangxiaoxiao',sex :'nv'};
// Object.assign(obj2,obj1);
// obj1.flag.x = 1000;  //浅拷贝 只有一层 因此第二层的flag变的时候两个都会改变
// console.log(obj1);
// console.log(obj2);
// console.log(obj1 === obj2);
// console.log(obj1.flag === obj2.flag);


//对象序列化
// let obj = {name: 'luojinsheng', age: 20};
// console.log(obj);
//
// let str = `{"name": "${obj.name}", age: ${obj.age}}`;
// console.log(str);
//对象转为字符串
// console.log(JSON.stringify(obj));
//
// let tmp = {name: 'luojinsheng', age: 20, ooo: {xxx: [1, 2, 300]}};
// console.log(JSON.stringify(tmp));

// let str = '{"name":"luojinsheng","age":20,"ooo":{"xxx":[1,2,300]}}';
// let json = JSON.parse(str);  //字符串解析成对象
// console.log(json.name);
// console.log(json.ooo.xxx[2]);

// let str1 = '{"name":"luojinsheng","age":20}'; //最外层只能是对象和数组
// let str2 = `[1,2,300, {"name": "luodada"}]`; //必须用双引号
// let json1 = JSON.parse(str1);
// console.log(json1.name);
// let json2 = JSON.parse(str2);
// console.log(json2[3].name);


//异常处理
let obj = {
    name: "luojinsheng",
    test: function () {
        console.log(this.name);
    }
};

function func(tmpObj) {
    try {
        tmpObj.test();
    } catch (e) {
        console.log("catch");
    } finally {
        console.log("finally");
    }
    console.log("func");
}

func(obj);


// let a = 100;
// let b = 0;
// if (b === 0) throw new Error("除数不能为0");
// console.log(a / b);



